package cn.example.aapplication1;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;

public class Main2Activity extends AppCompatActivity implements View.OnClickListener{

    private static final String TAG = "Main2Activity";

    private Button button;
    private Button btn_backdata;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main2);

        button = findViewById(R.id.btn_jumpfisrst);
        btn_backdata=findViewById(R.id.btn_backdata);
        button.setOnClickListener(this);
        btn_backdata.setOnClickListener(this);

        /*
        处理传过来的数据
         */
        Intent intent = Main2Activity.this.getIntent();
        String data1 = intent.getStringExtra("data1");
        Log.d(TAG, "onCreate: "+data1);
    }
    /**
     * 按钮的back的数据返回
     */
    @Override
    public void onBackPressed() {
        Intent inte2 = new Intent(Main2Activity.this, MainActivity.class);
        inte2.putExtra("back data",this.getClass().getSimpleName());
        this.setResult(this.RESULT_OK,inte2);
        finish();
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()){
            case R.id.btn_jumpfisrst:
                Intent intent = new Intent(Main2Activity.this, MainActivity.class);
                startActivity(intent);
                break;
            case R.id.btn_backdata:
                /*
                处理返回mainactivity的数据
                 */
                Intent inte2 = new Intent(Main2Activity.this, MainActivity.class);
                inte2.putExtra("back data",this.getClass().getSimpleName());
                this.setResult(this.RESULT_OK,inte2);
                finish();
                break;
        }
    }
}
